package in.util;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class TestEnv {
	class ThreadTest1 implements Runnable {
		boolean done = false;
		
		public void terminateInstance(){
			done = true;
		}
		@Override
		public void run() {
			int count = 0;
			while (done != true) {
				count++;
				try {
					Thread.sleep(2000);
				} catch (InterruptedException ex) {
				}
				System.out.println("In the loop " + count);
			}
		}
	}
	
	private static Logger logger = Logger.getLogger(TestEnv.class);
	private static TestEnv testEnv;
	protected static ThreadGroup threadGroup;
	
	public TestEnv(){
		threadGroup = new ThreadGroup("TestThread");
	}
	
	public static void main(String[] args) {
		BasicConfigurator.configure();
		
		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() {
				System.out.println("Shutdown. Do last things.");
				// while (true){
				// try {
				// Thread.sleep(2000);
				// } catch (InterruptedException e) {
				// e.printStackTrace();
				// }
				// System.out.println("Shutdown do Running forever");
				// }
			}
		});
		
		testEnv = new TestEnv();
		System.out.println("Let's take a break...");
		ThreadTest1 tt1 = testEnv.new ThreadTest1();
		Thread thread = new Thread(threadGroup, tt1, "Thread1");
		thread.start();
		// int count = 0;

		// while (true){
		// count++;
		// try {
		// Thread.sleep(2000);
		// } catch (InterruptedException ex) {
		// }
		// System.out.println("In the loop " + count);
		// if (count == 4){
		// System.exit(0);
		// }
		// }
	}
}